CC = g++
CPP = g++
CFLAGS = -fPIC -std=c++11 -I../
LIBS = -L/usr/local/lib -lopencv_imgcodecs -lopencv_imgproc -lopencv_core \
	    -L/usr/local/share/OpenCV/3rdparty/lib -Wl,-Bstatic -littnotify -llibjasper -llibjpeg-turbo -llibpng -llibprotobuf -llibwebp -lquirc -llibtiff
LIBS += -ldl -Wl,-Bdynamic -lm

LUA_SRC = $(wildcard ../lua/*.c)
LUA_OBJS = $(patsubst %.c, ../obj/%.o, $(notdir $(LUA_SRC)))
MY_SRC = luacv.cpp
MY_OBJS = $(patsubst %.cpp, ../obj/%.o,$(MY_SRC))

all: $(MY_OBJS) $(LUA_OBJS)
	if [ ! -x obj ]; then mkdir obj; fi
	$(CPP) $(CFLAGS) -o lua_match_template.so -shared $(MY_OBJS) $(LUA_OBJS) $(LIBS)

test: $(MY_OBJS) $(LUA_OBJS)
	if [ ! -x obj ]; then mkdir obj; fi
	$(CPP) $(CFLAGS) -o test $(MY_OBJS) $(LUA_OBJS) $(LIBS) 

$(MY_OBJS): $(MY_SRC)
	$(CPP) -g $(CFLAGS) -c -o $@ $<

$(LUA_OBJS): $(LUA_SRC)
	cd ../lua && make o
	mv ../lua/*.o ../obj
	cd ..

clean:
	rm -f ../test
	rm -f ../obj/*
	rm test

show:
	@echo $(SRC)
	@echo $(OBJS)